package org.appfuse.dao.hibernate;

// default package

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.appfuse.dao.BasicInfoDao;
import org.appfuse.model.BasicInfo;
import org.hibernate.FlushMode;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class BasicInfo.
 * 
 * @see .BasicInfo
 * @author MyEclipse Persistence Tools
 */

public class BasicInfoDaoHibernate extends BaseDaoHibernate implements
		BasicInfoDao {
	private static final Log log = LogFactory.getLog(BasicInfoDao.class);

	// property constants
	public static final String XM = "xm";

	public static final String XB = "xb";

	public static final String MZ = "mz";

	public static final String JG = "jg";

	public static final String CYM = "cym";

	public static final String CJGZRQ = "cjgzrq";

	public static final String GLJZZ = "gljzz";

	public static final String CSD = "csd";

	public static final String SFZHM = "sfzhm";

	public static final String JTZZ = "jtzz";

	public static final String YB = "yb";

	public static final String ZZMM = "zzmm";

	public static final String CJZZRQ = "cjzzrq";

	public static final String ZZDH = "zzdh";

	public static final String DWDH = "dwdh";

	public static final String QTTXFS = "qttxfs";

	public static final String RSGXSZDW = "rsgxszdw";

	public static final String GZGXSZDW = "gzgxszdw";

	public static final String USERID = "userId";

	public void save(BasicInfo transientInstance) {
		log.debug("saving BasicInfo instance");
		try {
			getSession().setFlushMode(FlushMode.AUTO);
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void update(BasicInfo transientInstance) {
		log.debug("updating BasicInfo instance");
		try {
			getSession().setFlushMode(FlushMode.AUTO);
			getSession().update(transientInstance);
			log.debug("update successful");
		} catch (Exception re) {
			log.error("update failed", re);
			throw new RuntimeException(re);
		}
	}

	public void delete(BasicInfo persistentInstance) {
		log.debug("deleting BasicInfo instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public BasicInfo findById(java.lang.String id) {
		log.debug("getting BasicInfo instance with id: " + id);
		try {
			/*
			 * BasicInfo instance = (BasicInfo) getSession() .get("BasicInfo",
			 * id);
			 */
			BasicInfo instance = (BasicInfo) getHibernateTemplate().get(
					BasicInfo.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(BasicInfo instance) {
		log.debug("finding BasicInfo instance by example");
		try {
			List results = getSession().createCriteria("BasicInfo").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding BasicInfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			/*
			 * String queryString = "from BasicInfo as model where model." +
			 * propertyName + "= ?";
			 * getHibernateTemplate().findByNamedParam(arg0, arg1, arg2) Query
			 * queryObject = getSession().createQuery(queryString);
			 * queryObject.setParameter(0, value); return queryObject.list();
			 */
			String queryString = "from BasicInfo as model where model."
					+ propertyName + "= :property";

			return getHibernateTemplate().findByNamedParam(queryString,
					"property", value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserId(String userId) {
		return null;//findByProperty(USERID, userId);
	}

	public List findByXm(Object xm) {
		return findByProperty(XM, xm);
	}

	public List findByXb(Object xb) {
		return findByProperty(XB, xb);
	}

	public List findByMz(Object mz) {
		return findByProperty(MZ, mz);
	}

	public List findByJg(Object jg) {
		return findByProperty(JG, jg);
	}

	public List findByCym(Object cym) {
		return findByProperty(CYM, cym);
	}

	public List findByCjgzrq(Object cjgzrq) {
		return findByProperty(CJGZRQ, cjgzrq);
	}

	public List findByGljzz(Object gljzz) {
		return findByProperty(GLJZZ, gljzz);
	}

	public List findByCsd(Object csd) {
		return findByProperty(CSD, csd);
	}

	public List findBySfzhm(Object sfzhm) {
		return findByProperty(SFZHM, sfzhm);
	}

	public List findByJtzz(Object jtzz) {
		return findByProperty(JTZZ, jtzz);
	}

	public List findByYb(Object yb) {
		return findByProperty(YB, yb);
	}

	public List findByZzmm(Object zzmm) {
		return findByProperty(ZZMM, zzmm);
	}

	public List findByCjzzrq(Object cjzzrq) {
		return findByProperty(CJZZRQ, cjzzrq);
	}

	public List findByZzdh(Object zzdh) {
		return findByProperty(ZZDH, zzdh);
	}

	public List findByDwdh(Object dwdh) {
		return findByProperty(DWDH, dwdh);
	}

	public List findByQttxfs(Object qttxfs) {
		return findByProperty(QTTXFS, qttxfs);
	}

	public List findByRsgxszdw(Object rsgxszdw) {
		return findByProperty(RSGXSZDW, rsgxszdw);
	}

	public List findByGzgxszdw(Object gzgxszdw) {
		return findByProperty(GZGXSZDW, gzgxszdw);
	}

	public List findAll() {
		log.debug("finding all BasicInfo instances");
		try {
			String queryString = "from BasicInfo";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public BasicInfo merge(BasicInfo detachedInstance) {
		log.debug("merging BasicInfo instance");
		try {
			BasicInfo result = (BasicInfo) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(BasicInfo instance) {
		log.debug("attaching dirty BasicInfo instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(BasicInfo instance) {
		log.debug("attaching clean BasicInfo instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}